import {
    Goodsinfo,
    TradeAddress,
    indent
} from "@/api"

const actions = {
    async trade(miniStore) {
        const re = await Goodsinfo()
        if (re.code === 200) {
            miniStore.commit("SET_PAYINFO_STATE", re.data)
        } else {
            return Promise.reject(new Error(re.message))
        }
    },

    async Address(miniStore) {
        const re = await TradeAddress()
        if (re.code === 200) {
            miniStore.commit("SET_TRADEADDRESS_STATE", re.data)
        } else {
            return Promise.reject(new Error(re.message))
        }
    },

    async GetIndentNum(miniStore, {
        tradeNo,
        orderInfo
    }) {
        const re = await indent(tradeNo, orderInfo)
        if (re.code === 200) {
            miniStore.commit("SET_INDENT_STATE", re.data)
            return re.data
        } else {
            return Promise.reject(new Error(re.message))
        }
    }
};
const mutations = {
    SET_PAYINFO_STATE(state, value) {
        state.goodlistinfo = value
    },
    SET_TRADEADDRESS_STATE(state, value) {
        state.UserTradeAddress = value
    },
    SET_INDENT_STATE(state, value) {
        state.NUM = value
    }
};
const state = {
    goodlistinfo: {},
    UserTradeAddress: [],
    NUM: ""
};
const getters = {

}

export default {
    actions,
    mutations,
    state,
    getters
}